// 83. 删除排序链表中的重复元素

import { ListNode } from "../1224";

/**
 * Definition for singly-linked list.
 * class ListNode {
 *     val: number
 *     next: ListNode | null
 *     constructor(val?: number, next?: ListNode | null) {
 *         this.val = (val===undefined ? 0 : val)
 *         this.next = (next===undefined ? null : next)
 *     }
 * }
 */

function deleteDuplicates(head: ListNode | null): ListNode | null {
  if (!head) return null;
  let temp = head;
  while (temp.next && temp) {
    const next = temp.next;
    if (next.val === temp.val) {
      temp.next = next.next;
    } else {
      temp = next;
    }
  }

  return head;
}
